<?php
namespace Home\Controller;
use Think\Controller;

class UserController extends Controller
{
	public function index(){
		$data  = M("user");
        $count = $data->where('1=1')->count();
        
        $page  = new \Think\Page($count,C("PAGESIZE"));
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
    	
    	$list  = $data->where("1=1")->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
        $show  = $page->show();
    	
    	$this->assign( "list", $list);
    	$this->assign( "page", $show);
        $this->display();
    
    }
   
    public function deletes(){
    
    	$ajax = I('post.id');
    	$data = M('user');
    	$data->delete($ajax);
  
    }
   
    public function inserts(){
    	
    	 if($_POST){
    		
    		
                $data['username']   = I('post.username');
                $data['password']   = sha1(I('post.password'));
                $data['intro']      = I('post.intro');
   
		    	$inst = M('user');
		    	$inst->add($data);
		    	$this->success('添加成功', '',0);

    		} else {
    			$this->error('添加失败！', '',0);
    		}			
    }
    
    public function renewal(){

    	if($_POST){
    		
            $data['id']        = I('post.id');
            $data['username']  = I('post.username');
    		$data['intro']     = I('post.intro');
    		$data['password']  = sha1(I('post.password'));
    		$upt = M('user');
    		$upt->where("id={$data['id']}")->save($data);

		} else {
            $this->error('编辑数据失败，请重新编辑！', '',0);
        }  
    }
	
}